package com.sfj.system.controller;

import com.kaka.starter.control.dto.ResultBean;
import com.sfj.system.dto.task.ProblemQueryProcessDTO;
import com.sfj.system.dto.task.TaskAddDTO;
import com.sfj.system.dto.task.TaskReviewDTO;
import com.sfj.system.entity.ProblemProcessEntity;
import com.sfj.system.service.task.ProblemProcessService;
import com.sfj.system.service.task.TaskQueryService;
import com.sfj.system.service.task.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author kaka
 * @Date 2025/07/01
 */
@RestController
@RequestMapping("task")
@Api(tags = "督察任务管理")
public class TaskController {
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskQueryService taskQueryService;
    @Autowired
    private ProblemProcessService problemProcessService;

    @PostMapping("/create")
    @ApiOperation(value = "创建督办任务", notes = "创建新的督办任务")
    public ResultBean create(@RequestBody TaskAddDTO taskDTO) {
        taskService.createTask(taskDTO);
        return ResultBean.succeed();
    }

    @PostMapping("/upd")
    @ApiOperation(value = "更新督办任务", notes = "更新督办任务信息")
    public ResultBean update(@RequestBody TaskAddDTO taskDTO) {
        taskService.updateTask(taskDTO);
        return ResultBean.succeed();
    }

    @GetMapping("/delete/{taskId}")
    @ApiOperation(value = "删除督办任务", notes = "根据ID删除督办任务")
    public ResultBean delete(@PathVariable Integer taskId) {
        taskService.deleteTask(taskId);
        return ResultBean.succeed();
    }

    @PostMapping("/withdraw")
    @ApiOperation(value = "撤回任务", notes = "撤回任务")
    public ResultBean withdraw(@RequestBody Integer taskId) {
        taskService.withdrawTask(taskId);
        return ResultBean.succeed();
    }

    @PostMapping("/review")
    @ApiOperation(value = "审批任务", notes = "审批任务")
    public ResultBean review(@RequestBody TaskReviewDTO taskReviewDTO) {
        taskService.reviewTask(taskReviewDTO);
        return ResultBean.succeed();
    }

    @PostMapping("/receive")
    @ApiOperation(value = "接收任务", notes = "接收任务")
    public ResultBean receive(@RequestBody Integer taskId) {
        taskService.receive(taskId);
        return ResultBean.succeed();
    }
    @PostMapping("/processed")
    @ApiOperation(value = "提交反馈任务", notes = "提交反馈任务")
    public ResultBean processed(@RequestBody Integer taskId) {
        taskService.processed(taskId);
        return ResultBean.succeed();
    }

    @PostMapping("/process")
    @ApiOperation(value = "整改问题反馈", notes = "整改问题反馈")
    public ResultBean process(@RequestBody ProblemProcessEntity problemProcessEntity) {
        taskService.process(problemProcessEntity);
        return ResultBean.succeed();
    }

    @PostMapping("/queryByProcess")
    @ApiOperation(value = "查询反馈任务", notes = "查询反馈任务")
    public ResultBean process(@RequestBody ProblemQueryProcessDTO problemQueryProcessDTO) {
        problemProcessService.getProblemProcessById(problemQueryProcessDTO.getProblemId(),
                problemQueryProcessDTO.getTaskId(),problemQueryProcessDTO.getRfUser());
        return ResultBean.succeed();
    }


}
